package com.calenda.setevent.adapter;

import java.util.ArrayList;

import com.calenda.setevent.R;
import com.calenda.setevent.entity.GroupEntity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridGroupAdapter extends BaseAdapter {
	private ArrayList<GroupEntity> arrData;
	private LayoutInflater inflater;

	public GridGroupAdapter(Context context, ArrayList<GroupEntity> groupEntity) {
		inflater = LayoutInflater.from(context);
		this.arrData = groupEntity;
	}

	@Override
	public int getCount() {
		return arrData.size();
	}

	@Override
	public GroupEntity getItem(int arg0) {
		return arrData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View v, ViewGroup vg) {
		GroupEntity groupEntity = getItem(position);
		ViewHolder viewHolder;

		if (v == null) {
			v = inflater.inflate(R.layout.lst_group_item, null);
			viewHolder = new ViewHolder(v);
		} else {
			viewHolder = (ViewHolder) v.getTag();
		}

		viewHolder.tvNameGroup.setText(groupEntity.getGroupid());

		return v;
	}

	class ViewHolder {
		private TextView tvNameGroup;
		private ImageView imgAvatar;

		public ViewHolder(View v) {
			tvNameGroup = (TextView) v.findViewById(R.id.tvNameGroup);
			imgAvatar = (ImageView) v.findViewById(R.id.imgAvatar);
			v.setTag(this);
		}
	}

}
